<template>
  <div class="about">
    <div class="header">
      <br />
      <div class="top">
        <van-tabs v-model="active" type="card">
          <van-tab title="快递配送">
            <div class="tabLeft" v-if="addressInfo[0]">
              <div class="one" v-for="(v, i) in addressInfo" :key="i">
                <h3>{{ v.real_name }}&emsp;{{ v.phone }}</h3>
                <p>
                  <span style="color: red">[默认]</span>
                  {{ v.province }}{{ v.district }}{{ v.detail }}
                </p>
              </div>
              <div class="two">
                <van-icon name="arrow" />
              </div>
            </div>
            <div class="leftData">
              <div class="leftDataOne" v-for="(v, i) in cartInfo" :key="i">
                <div>共{{ v.cart_num }}件商品</div>
                <hr />
                <div>
                  <!-- 渲染数据 -->
                  <dl>
                    <dt><img :src="v.productInfo.image" alt="" /></dt>
                    <dd class="dldd">
                      <span>{{ v.productInfo.store_name }}</span>
                      <div class="box1"></div>
                      <span>x{{ v.cart_num }}</span>
                    </dd>
                    <dd>{{ v.productInfo.attrInfo.suk }}</dd>
                    <dd>
                      <span style="color: red">
                        ￥{{ v.productInfo.price }}
                      </span>
                    </dd>
                  </dl>
                </div>
              </div>
            </div>
            <div class="leftDataTwo">
              <ul>
                <li @click="showPopup">
                  <span>优惠券</span>
                  <div class="box1"></div>
                  <span><van-icon name="arrow" /></span>
                </li>
                <li>
                  <span>积分抵扣</span>
                  <div class="box1"></div>
                  <span style="color: #ccc"
                    >当前积分<span style="color: red">
                      ￥{{ userInfo.integral }}
                    </span>
                  </span>
                </li>
                <li>
                  <span>快递费用</span>
                  <div class="box1"></div>
                  <span style="color: red"
                    >￥{{ priceGroup.storePostage }}</span
                  >
                </li>
                <li>
                  <div><p>备注信息:</p></div>
                </li>
                <li style="height: 80px">
                  <textarea
                    name=""
                    id=""
                    cols="30"
                    rows="30"
                    placeholder="   添加备注(150字以内)"
                  ></textarea>
                </li>
              </ul>
            </div>
            <div class="payment">
              <van-cell
                title="微信支付"
                icon="comment-circle-o"
                value="微信快捷支付"
                @click="WechatPay"
                class="WechatPay"
              />
              <van-cell
                title="余额支付"
                icon="gold-coin-o"
                :value="userInfo.now_money"
                class="balancepaid"
                @click="balancepaid"
              />
              <van-cell
                title="线下支付"
                icon="credit-pay"
                value="线下支付"
                class="offlinepayment"
                @click="offlinepayment"
              />
            </div>
            <br />
            <button
              style="
                width: 100px;
                height: 30px;
                border-radius: 25px;
                background: red;
                color: white;
                border: none;
                margin-left: 2%;
              "
              @click="zhif"
            >
              支付
            </button>
          </van-tab>
          <van-tab title="到店自提">
            <div class="tabRight">&emsp;暂无店面信息</div>
            <div class="leftData">
              <div class="leftDataOne" v-for="(v, i) in cartInfo" :key="i">
                <div>共{{ v.cart_num }}件商品</div>
                <hr />
                <div>
                  <dl>
                    <dt><img :src="v.productInfo.image" alt="" /></dt>
                    <dd class="dldd">
                      <span>{{ v.productInfo.store_name }}</span>
                      <div class="box1"></div>
                      <span>x{{ v.cart_num }}</span>
                    </dd>
                    <dd>{{ v.productInfo.attrInfo.suk }}</dd>
                    <dd>
                      <span style="color: red"
                        >￥{{ v.productInfo.price }}</span
                      >
                    </dd>
                  </dl>
                </div>
              </div>
            </div>
            <div class="leftDataTwo">
              <ul>
                <li @click="showPopup">
                  <span>优惠券</span>
                  <div class="box1"></div>
                  <span><van-icon name="arrow" /></span>
                </li>
                <li>
                  <span>积分抵扣</span>
                  <div class="box1"></div>
                  <span style="color: #ccc"
                    >当前积分<span style="color: red">
                      ￥{{ userInfo.integral }}
                    </span>
                  </span>
                </li>
                <li>
                  <span>联系人</span>
                  <div class="box1"></div>
                  <span
                    ><input type="text" placeholder="请填写您的联系姓名"
                  /></span>
                </li>
                <li>
                  <span>联系电话</span>
                  <div class="box1"></div>
                  <span
                    ><input type="text" placeholder="请填写您的联系电话"
                  /></span>
                </li>
                <li>
                  <div><p>备注信息:</p></div>
                </li>
                <li style="height: 80px">
                  <textarea
                    name=""
                    id=""
                    cols="30"
                    rows="30"
                    placeholder="   添加备注(150字以内)"
                  ></textarea>
                </li>
              </ul>
            </div>
            <div class="payment">
              <van-cell
                title="微信支付"
                icon="comment-circle-o"
                value="微信快捷支付"
                @click="WechatPay"
                class="WechatPay"
              />
              <van-cell
                title="余额支付"
                icon="gold-coin-o"
                :value="userInfo.now_money"
                class="balancepaid"
                @click="balancepaid"
              />
              <van-cell
                title="线下支付"
                icon="credit-pay"
                value="线下支付"
                class="offlinepayment"
                @click="offlinepayment"
              />
            </div>
          </van-tab>
        </van-tabs>
      </div>
    </div>
    <!-- 优惠券弹窗 -->
    <van-popup
      v-model="showCoun"
      round
      closeable
      close-icon="close"
      position="bottom"
      :style="{ height: '60%', background: '#eee' }"
    >
      <DetailCoupon></DetailCoupon>
    </van-popup>
  </div>
</template>
<script>
import { geCloses } from "@/api/request";
// 优惠券组件
import DetailCoupon from "@/components/detailCoupon.vue";
import axios from "axios";
export default {
  data() {
    return {
      active: 2,
      // 承接地址接口
      addressInfo: [],
      cartInfo: [],
      userInfo: [],
      priceGroup: [],
      // 优惠券
      showCoun: false,
      priceValue: [],
    };
  },
  methods: {
    // 优惠券
    showPopup() {
      this.showCoun = true;
    },
    // 微信支付
    WechatPay() {
      console.log("微信支付");
      document.querySelector(".WechatPay").style.color = "red";
      document.querySelector(".balancepaid").style.color = "black";
      document.querySelector(".offlinepayment").style.color = "black";
    },
    // 余额支付
    balancepaid() {
      console.log("余额支付");
      document.querySelector(".WechatPay").style.color = "black";
      document.querySelector(".balancepaid").style.color = "red";
      document.querySelector(".offlinepayment").style.color = "black";
    },
    // 线下支付
    offlinepayment() {
      console.log("线下支付");
      document.querySelector(".WechatPay").style.color = "black";
      document.querySelector(".balancepaid").style.color = "black";
      document.querySelector(".offlinepayment").style.color = "red";
    },
    // 支付沙盒
    zhif() {
      // console.log();
      axios({
        url: `http://localhost:8090/api/alipayWap?id=${
          this.$route.query.cartid
        }&subject=${this.userInfo.nickname}&body=${
          this.userInfo.real_name
        }&amount=${
          Number(this.priceGroup.storePostage) +
          Number(this.priceGroup.totalPrice)
        }&returnUrl=http://localhost:8080/`,
        method: "get",
      }).then((res) => {
        if (res.data.code === 200) {
          window.location.assign(res.data.result);
        }
      });
    },
  },
  created() {
    // 结算接口获取
    geCloses(this.$route.query.cartid, this.$route.query.new).then((res) => {
      // 地址接口
      this.addressInfo = [res.data.data.addressInfo];
      // 商品
      this.cartInfo = res.data.data.cartInfo;
      // 积分
      this.userInfo = res.data.data.userInfo;
      // 快递费用
      this.priceGroup = res.data.data.priceGroup;
    });
  },
  components: {
    DetailCoupon,
  },
};
</script>
<style lang="less" scoped>
* {
  margin: 0;
}
.header {
  width: 100%;
  height: 155px;
  background: linear-gradient(180deg, #e93323 0, #f5f5f5);
}

.van-tab__pane {
  width: 100%;
  //   margin-left: 4%;
  background: none;
}
.tabLeft {
  width: 92%;
  display: flex;
  margin-left: 4%;
  height: 100px;
  background: white;
  .one {
    width: 90%;
    margin-left: 5%;
    margin-top: 10px;
  }
  .two {
    line-height: 70px;
    font-size: 26px;
  }
}
// 快递配送
.leftData {
  width: 100%;
  margin-top: 5%;
  background: white;
  hr {
    margin-top: 10px;
  }
  .leftDataOne {
    width: 92%;
    height: 150px;
    margin-left: 4%;
    dl {
      width: 100%;
      height: 100%;
      dt {
        width: 25%;
        float: left;
        img {
          width: 80px;
          height: 100px;
        }
      }
      dd {
        margin-top: 2%;
      }
      .dldd {
        display: flex;

        .box1 {
          flex: 1;
        }
      }
    }
  }
}
// 到店自提
.tabRight {
  width: 92%;
  display: flex;
  margin-left: 4%;
  height: 70px;
  line-height: 70px;
  background: white;
  .one {
    width: 90%;
    margin-left: 5%;
    margin-top: 10px;
  }
  .two {
    line-height: 70px;
    font-size: 26px;
  }
  .leftData {
    width: 100%;
    margin-top: 5%;
    background: white;
    hr {
      margin-top: 10px;
    }
    .leftDataOne {
      width: 92%;
      height: 130px;
      margin-left: 4%;
      dl {
        width: 100%;
        height: 100%;
        dt {
          width: 25%;
          float: left;
          img {
            width: 80px;
            height: 80px;
          }
        }
        dd {
          margin-top: 2%;
        }
        .dldd {
          display: flex;
          .box1 {
            flex: 1;
          }
        }
      }
    }
  }
}
.leftDataTwo {
  margin-top: 2%;
  width: 100%;
  background: white;
  ul {
    width: 92%;
    margin-left: 4%;
    li {
      display: flex;
      height: 40px;
      line-height: 40px;
      border-bottom: 1px solid #ccc;
      input {
        border: none;
        height: 20px;
      }
      .box1 {
        flex: 1;
      }
      textarea {
        width: 100%;
        height: 70px;
        border: none;
        background: #eee;
      }
    }
  }
}
.payment {
  margin-top: 2%;
}
</style>